package com.roger.springcloudGreenwich.util;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        /*
         * author:java265.com
         * list去重操作示例分享
         * */
        List<User> list = new ArrayList<>();
        list.add(new User("1","xiaoming"));
        list.add(new User("2","xiaoming"));
        list.add(new User("3","xiaoming"));
        list.add(new User("4","xiaoming"));
        list.add(new User("4","xiaoming"));

        System.out.println(list);
        System.out.println("------------");
        //去重
        Set<User> set = new HashSet<>();
        set.addAll(list);
        System.out.println(set);
    }
}

class User{
    private String id;
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public User() {
    }

    public  User(String id,String name){
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return Objects.equals(id, user.id) &&
                Objects.equals(name, user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }


}
